# Maintainer: Noel Kuntze <noel.kuntze@contauro.com>
pkgname=grommunio-dav
pkgdesc="CalDAV and CardDAV interface for grommunio"
pkgver=2.0_git20240118
pkgrel=0
arch="noarch !riscv64"
url="http://www.kopano.com/"
license="AGPL-3.0-only"
options="!check" # No test suite
_php=php83
install="$pkgname.pre-install"
depends="grommunio-gromox
	grommunio-mapi-header-php
	$_php
	$_php-ctype
	$_php-curl
	$_php-dom
	$_php-iconv
	$_php-mbstring
	$_php-pdo_sqlite
	$_php-xml
	$_php-xmlreader
	$_php-xmlwriter
	"

_commithash=e16f8a2e909c0b064a456266034696949218e5df
#_commithash=45e9e18483bc5ad840e15c464b954ffb1c14ce40

source="$pkgname-$pkgver.tar.gz::https://github.com/grommunio/grommunio-dav/archive/$_commithash.tar.gz
	$pkgname-$pkgver-vendor.tar.gz::https://nerd.hu/distfiles/grommunio-dav-$_commithash-vendor.tar.gz
"

builddir="$srcdir/grommunio-dav-$_commithash/"

build() {
	:
}

package() {
	# webapp
	install -dm755 "$pkgdir/usr/share/webapps/$pkgname/"
	cp -rp -- * "$pkgdir/usr/share/webapps/$pkgname/"

	# vendor libraries
	cp -rp "$srcdir/vendor" "$pkgdir/usr/share/webapps/$pkgname/"

	# license
	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

	# nginx conf
	sed -i "s@/usr/share/grommunio-dav/@/usr/share/webapps/grommunio-dav/@" build/grommunio-dav.conf
	install -Dpm644 build/grommunio-dav.conf "$pkgdir/usr/share/grommunio-common/nginx/locations.d/grommunio-dav.conf"
	install -Dpm644 build/grommunio-dav-upstream.conf "$pkgdir/usr/share/grommunio-common/nginx/upstreams.d/grommunio-dav.conf"

	# php-fpm
	install -Dpm644 build/pool-grommunio-dav.conf "$pkgdir/etc/$_php/php-fpm.d/pool-grommunio-dav.conf"

	# logrotate
	install -Dm644 build/grommunio-dav.lr "$pkgdir/etc/logrotate.d/grommunio-dav"

	# config
	install -Dm644 config.php "$pkgdir/etc/grommunio-dav/config.php"
	ln -sf "/etc/grommunio-dav/config.php" "$pkgdir/usr/share/webapps/grommunio-dav/config.php"
	install -Dm644 glogger.ini "$pkgdir/etc/grommunio-dav/glogger.ini"
	ln -sf "/etc/grommunio-dav/glogger.ini" "$pkgdir/usr/share/webapps/grommunio-dav/glogger.ini"

	# remove unnecessary files
	rm -rf "$pkgdir/usr/share/webapps/grommunio-dav/build"
	rm -rf "$pkgdir/usr/share/webapps/grommunio-dav/tests"
	rm -f "$pkgdir/usr/share/webapps/grommunio-dav/LICENSE"
	rm -f "$pkgdir/usr/share/webapps/grommunio-dav/README.rst"
	rm -f "$pkgdir/usr/share/webapps/grommunio-dav/composer.*"

}

sha512sums="
f7a16566053650c8b1d7a7e8ebd062e74317f93a728f0ee4409476363dc679d9998485ee0bf8db8bbe1f6443eb5d39d7c20c1eba39846a18d4eb88bf37b5f698  grommunio-dav-2.0_git20240118.tar.gz
b44a1b8a7c8276c319d9fa2f283d59c11fde060d0ec6364a5b587157f1fd2c5bbda6cd0d596a081815556f4da0adf6f854ce116b0f21eaa95ac9f60e4fd72f5c  grommunio-dav-2.0_git20240118-vendor.tar.gz
"
